<?php

	/**
	* Permission Check Block. Check give permission 
	* Only use this block when you want to check permission of other module
	* 
	* @author trungdt
	* @since Apr, 2012
	* @version 1.0
	* @copyright ABSoft Viet Nam
	* 
	* {permission_check permission='abc,def,ghi' module='fds' id="block_id"}
	* {/permission_check}
	* 
	* There are 2 type of using this block
	* {permission_check id="block_id"}
	*   {permission_check permission='abc,def,ghi' module='fds' id="block_id"}
	*   {/permission_check}
	* {/permission_check}
	* 
	* If No sub permission_check block has permission, then master permission check block will not shown anything 
	*/

	function smarty_block_permission_check($params,$content,&$smarty, &$repeat) {
		$id="permission_block";
		
		if (isset($params['id']))
				$id=$params['id'];
		
		if (!$content) 
		{
			exponent_sessions_set("_permission_block_{$id}",0);// set permission block cache that there is no permission
		}
		else
		{
			// get params
			$permission="";
			$module="";
			$src="";

			if (!(isset($params['permission']) && isset($params['module'])))
			{
				// close of permission master block
				if (exponent_sessions_get("_permission_block_{$id}"))
					return $content;
				else
					return "";
			}
			else
			{
				// close of sub
				$permission = $params['level'];
				$module = $params['module'];

				$permission = explode(",",$permission);
				foreach ($permission as $k=>$v)
					$permission[$k]=trim($v);

				if (exponent_permissions_checkOnModule($permission, $module))
					{
						exponent_sessions_set("_permission_block_{$id}",true);
						return $content;
					}
				else
					return "";
			}
		}
	}

?>